<?php
/**
 * @package Joomla
 * @subpackage Component
 * @license GNU/GPL
 * @author Joomlart.com
 * @version 1.0
 */
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die();

jimport( 'joomla.application.component.view' );

/**
 * News View
 * @package Joomlart
 * @subpackage Components
 */
class JanewsViewfrontpage extends JView 
{
	function display($tpl = null)
	{
		if($this->getLayout() == 'form') {
			$this->_displayForm($tpl);
			return;
		}
		global $mainframe, $option;
		
		$filter_order		= $mainframe->getUserStateFromRequest( "$option.filter_order",		'filter_order',		's.id',	'cmd' );
		$filter_order_Dir	= $mainframe->getUserStateFromRequest( "$option.filter_order_Dir",	'filter_order_Dir',	'',				'word' );
		$limit		= $mainframe->getUserStateFromRequest( 'global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int' );
		$limitstart	= $mainframe->getUserStateFromRequest( $option.'.limitstart', 'limitstart', 0, 'int' );
		$model = $this->getModel();
		$frontpages = $model->getLists($filter_order, $filter_order_Dir, $limit, $limitstart);
		$this->assignRef('frontpages', $frontpages);
		$total = $model->getTotal();
		
		$lists['order_Dir']	= $filter_order_Dir;
		$lists['order']		= $filter_order;
		
		jimport('joomla.html.pagination');
		$pageNav = new JPagination( $total, $limitstart, $limit );
		
		$task = isset($_REQUEST['task'])?$_REQUEST['task']:'';
		
		$this->assignRef('lists', $lists);
		$this->assignRef('pageNav', $pageNav);
		$this->assignRef('task', $task);
		parent::display($tpl);
	}
	
	function _toolbarDefault()
	{
		$document = & JFactory::getDocument();
		$document->setTitle( JText::_('FRONTPAGE LAYOUT MANAGER') );
		JToolBarHelper::custom('todisplay','default','default','default',true,false);
		JToolBarHelper::title( JText::_( 'Frontpage Layout Manager' ), 'generic.png' );
		JToolBarHelper::deleteList();
		JToolBarHelper::editListX();
		JToolBarHelper::addNewX();
		JToolBarHelper::cancel('cancel','Close');
	}
	
	function _toolbarEdit($edit=false)
	{
		$text = ( $edit ? JText::_( 'Edit' ) : JText::_( 'New' ) );
		JToolBarHelper::title(  JText::_( 'FRONTPAGE LAYOUT' ).': <small><small>[ ' . $text.' ]</small></small>', 'generic.png' );
		JToolBarHelper::save();
	  JToolBarHelper::apply();
		if ($edit)
		  JToolBarHelper::cancel('cancel','Close');
		else
		  JToolBarHelper::cancel();
	}
	
	function _displayForm($tpl)
	{
		$cids = JRequest::getVar('cid',  0, '', 'array');
		$cid = (int)$cids[0];
		$model = $this->getModel();
		//$frontpage = $model->getFrontpageInfo($cid);
		$frontpage =& JTable::getInstance( 'janews_frontpage', 'Table' );
		$frontpage->load($cid);
		$headlines = $model->getListTemplates('headline');
		$blogs = $model->getListTemplates('blog');
		$list_secs = $model->getListSecs();
		$str_secids = ($cid > 0) ? $model->getStrSecIds($cid) : null;
		$secSelect = ($cid > 0) ? $model->getSelectedSecs($cid) : null;
		
		$this->assignRef('cid', $cid);
		$this->assignRef('frontpage', $frontpage);
		$this->assignRef('headlines', $headlines);
		$this->assignRef('blogs', $blogs);
		$this->assignRef('list_secs', $list_secs);
		$this->assignRef('str_secids', $str_secids);
		$this->assignRef('secSelect', $secSelect);
		
		parent::display($tpl);
	}
	
}
?>